class LTESearch extends View{
    constructor(rxp) {
        super(rxp);
        this.lteFunction = ['peakall','channel'];
    };
    open() {
        return super.open('ltesv','lte');
    };
    lteDo(r,d) {
        if (this.lteFunction.includes(r)) {
            return this.Do('lte'+r,d);   
        }
    };
}

class LTEView extends View {
    constructor(rxp) {
        super(rxp);
        this.lteFunction = [  'pss'
                            , 'scan'
                            , 'peak'
                            , 'cfo'
                        ];
        this.searcher = new LTESearch(rxp);
    };
    open() {
        return super.open('ltev','lte');
    };
    lteDo(r,d) {
        if (this.lteFunction.includes(r)) {
            return this.Do('lte'+r,d);   
        }
    };
    dummy(d) {};
    initWithCB(cbs,cb) {
        var setf = {setf:true};
        var first = new Req(this.rf.open('lte'),cbs["dev"]);
        first.then(this.rf.simpleDev('start'),cbs["start"])
             .then(this.open(),cbs["view"])
             .then(this.afcOff(),this.dummy)
             .then(this.resetPPM(),this.dummy)
             .then(this.lteDo('pss',setf),cbs["pss"])
             .then(this.lteDo('scan',setf),cbs["scan"])
             .then(this.lteDo('peak',setf),cbs["peak"])
             .then(this.lteDo('cfo',setf),cbs["cfo"])
             .then(this.afcOn(),this.dummy)
             .then(this.searcher.open(),cb);
        first.do();
    };
    defautCB() {
        return {
              "dev"   : console.log
            , "start" : console.log
            , "view"  : console.log
            , "pss"   : console.log
            , "scan"  : console.log
            , "peak"  : console.log
            , "cfo"   : console.log
        }
    };
    init() {
        var cbs = this.defautCB();
        this.initWithCB(cbs,this.dummy);
    };
    initview(el,cb) {
        var cbs = this.defautCB();
        cbs["scan"] = function(d) {
            console.log("scan",d)
            $(el).find('input').val(d[0].cid.toString())
        };
        cbs["peak"] = function(d) {
            console.log("peak",d)
            $(el).find('#pos').text(d.pos)
        };
        cbs["cfo"] = function(d) {
            console.log("cfo",d)
            $(el).find('#cfo').text(parseFloat(d.freqoff).toFixed(2))
        };
        this.initWithCB(cbs,cb);
    };
};
